<template>
  <view style="height:90vh;">
    <!-- 一级分类的名字 -->
    <!-- <view class="title-box ss-flex ss-col-center ss-row-center ss-p-b-30">
      <view class="title-line-left" />
      <view class="title-text ss-p-x-20">{{ props.data[activeMenu].name }}</view>
      <view class="title-line-right" />
       background-color: #6A645870;
       #A1958470
    </view> -->
    <!-- 二级分类的名字 -->
    <view 
      class="goods-item-box ss-flex ss-flex-wrap ss-p-b-20"
      :class="{ 'single-row': isChildrenOdd }"
    >
      <view
        class="goods-item"
        v-for="item in props.data[activeMenu].children"
        :key="item.id"
        @tap="
          sheep.$router.go('/pages/goods/list', {
            categoryId: item.id,
          })
        "
      >
        <image class="goods-img" :src="item.picUrl" mode="aspectFill" />
        <!-- <view class="ss-p-10">
          <view class="goods-title ss-line-1">{{ item.name }}</view>
        </view> -->
      </view>
    </view>
  </view>
</template>

<script setup>
  import sheep from '@/sheep';
  import { computed } from 'vue';

  const props = defineProps({
    data: {
      type: Object,
      default: () => ({}),
    },
    activeMenu: [Number, String],
  });

  // 判断子分类数量是否为奇数
  const isChildrenOdd = computed(() => {
    const children = props.data[props.activeMenu]?.children || [];
    return children.length % 2 === 1;
  });
</script>

<style lang="scss" scoped>
  .title-box {
    .title-line-left,
    .title-line-right {
      width: 15px;
      height: 1px;
      background: #d2d2d2;
    }
  }

  .goods-item {
    width: calc((100% - 30rpx) / 2);
    margin-right: 10rpx;
    margin-left: 10rpx;
    margin-bottom: 10rpx;

    &:nth-of-type(1n) {
      margin-right: 0;
    }

    .goods-img {
      width: 100%;
      height: 700rpx; /* 减小图片高度 */
    }

    .goods-title {
      font-size: 24rpx; /* 减小字体大小 */
      font-weight: bold;
      color: #333333;
      line-height: 32rpx;
      text-align: center;
    }

    .goods-price {
      color: $red;
      line-height: 40rpx;
    }
  }

  /* 单行布局样式 */
  .single-row {
    flex-direction: column;
    
    .goods-item {
      width: 100% !important;
      margin-right: 0 !important;
      margin-bottom: 20rpx;
      margin-top: 20rpx;
      text-align: center;

      &:nth-of-type(1n) {
        margin-top: 0;
        margin-bottom: 0;
      }
      
      .goods-img {
        width: calc(100% - 20rpx);
        height: 400rpx;
        margin-right: 20rpx;
      }

      .ss-p-10{
        display: none;
      }

      .goods-title {
        font-size: 28rpx;
        text-align: left;
        flex: 1;
      }
    }
  }
</style>
